package com.ruoyi.dangerControl.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.dangerControl.domain.HdProcess;
import com.ruoyi.dangerControl.dto.HdPunishDto;
import com.ruoyi.dangerControl.mapper.HdProcessMapper;
import com.ruoyi.dangerControl.vo.HdPunishVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.dangerControl.mapper.HdPunishMapper;
import com.ruoyi.dangerControl.domain.HdPunish;
import com.ruoyi.dangerControl.service.IHdPunishService;

/**
 * 隐患-处罚Service业务层处理
 *
 * @author lth
 * @date 2023-12-13
 */
@Service
public class HdPunishServiceImpl implements IHdPunishService
{
    @Autowired
    private HdPunishMapper hdPunishMapper;

    @Autowired
    private HdProcessMapper hdProcessMapper;
    /**
     * 查询隐患-处罚
     *
     * @param id 隐患-处罚主键
     * @return 隐患-处罚
     */
    @Override
    public HdPunish selectHdPunishById(Long id)
    {
        return hdPunishMapper.selectHdPunishById(id);
    }

    /**
     * 查询隐患-处罚列表
     *
     * @param hdPunish 隐患-处罚
     * @return 隐患-处罚
     */
    @Override
    public List<HdPunish> selectHdPunishList(HdPunish hdPunish)
    {
        return hdPunishMapper.selectHdPunishList(hdPunish);
    }

    /**
     * 新增隐患-处罚
     *
     * @param hdPunish 隐患-处罚
     * @return 结果
     */
    @Override
    public int insertHdPunish(HdPunish hdPunish)
    {
        return hdPunishMapper.insertHdPunish(hdPunish);
    }

    /**
     * 修改隐患-处罚
     *
     * @param hdPunish 隐患-处罚
     * @return 结果
     */
    @Override
    public int updateHdPunish(HdPunish hdPunish)
    {
        return hdPunishMapper.updateHdPunish(hdPunish);
    }

    /**
     * 批量删除隐患-处罚
     *
     * @param ids 需要删除的隐患-处罚主键
     * @return 结果
     */
    @Override
    public int deleteHdPunishByIds(Long[] ids)
    {
        return hdPunishMapper.deleteHdPunishByIds(ids);
    }

    /**
     * 删除隐患-处罚信息
     *
     * @param id 隐患-处罚主键
     * @return 结果
     */
    @Override
    public int deleteHdPunishById(Long id)
    {
        return hdPunishMapper.deleteHdPunishById(id);
    }

    /**     隐患-处罚列表
    * @Author lth
    * @Description //TODO
    * @Date 9:31 2024/1/4
    * @Param
    * @return
     **/
    @Override
    public List<HdPunishDto> getPunishList(HdPunishVo vo) {
        List<HdPunish> hdPunishList = hdPunishMapper.selectHdPunishList(null);
        System.out.println(hdPunishList);

        List<HdPunishDto> dtoList = hdPunishList.stream().map(hdPunish -> {
            HdPunishDto hdPunishDto = new HdPunishDto();
            BeanUtils.copyProperties(hdPunish, hdPunishDto);

            String code = hdPunish.getHdCode();
            HdProcess hdProcess = hdProcessMapper.getHdProcessByHdCode(code);

            hdPunishDto.setHdCode(code);
            hdPunishDto.setName(hdProcess.getName());
            hdPunishDto.setDangerContent(hdProcess.getContent());
            hdPunishDto.setTypeName(hdProcess.getTypeName());
            hdPunishDto.setLevelName(hdProcess.getLevelName());
            hdPunishDto.setPunishContent(hdPunish.getContent());

            hdPunishDto.setPunishPerson(null);

            return hdPunishDto;
        }).collect(Collectors.toList());
        return dtoList;
    }
}
